package com.ws.controller;

import com.ws.bean.Acl_user;
import com.ws.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/houTai")
public class HouTaiController {
    @Autowired
    Acl_UserController aclUserController;


    @RequestMapping("toindex")
    public String toindex(){
        return "admin/index";
    }
    @RequestMapping("towelcome")
    public String toleft(){
        return "admin/welcome";
    }
    @RequestMapping("login")
    public String login(@RequestParam("username")String username, @RequestParam("password")String password, HttpServletRequest request){
        Acl_user aclUser = aclUserController.login(username);
        if (aclUser!=null){
            boolean verify = SecurityUtils.verify(password, aclUser.getPassword());
            if (verify){
                request.getSession().setAttribute("aclUser",aclUser);
                return "redirect:/houTai/toindex";
            }
        }
            return "../login";
    }

}
